package com.flyqiu.flow.starter;

import com.flyqiu.flow.api.FlyQiuFlowConfig;
import com.flyqiu.flow.api.format.FlyQiuFlowBpmnFormatManage;
import com.flyqiu.flow.api.cache.FlyQiuFlowCacheManage;
import com.flyqiu.flow.api.candidate.FlyQiyFlowCandidateManage;
import com.flyqiu.flow.api.deploy.FlyQiuFlowDeployManage;
import com.flyqiu.flow.api.element.FlyQiuFlowElementManage;

import com.flyqiu.flow.api.script.FlyQiuFlowScriptActuatorManage;
import com.flyqiu.flow.api.script.FlyQiuFlowVarSerializeManage;
import com.flyqiu.flow.api.std.FlyQiuFlowObjectFactory;
import com.flyqiu.flow.core.DefaultFlowConfigImpl;
import com.flyqiu.flow.core.deploy.DefaultFlyQiuFlowDeployManage;
import com.flyqiu.flow.core.impl.DefaultFlowObjectFactory;
import com.flyqiu.flow.core.manage.*;
import com.flyqiu.flow.event.api.FlyQiuFlowEventManage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;


@Slf4j
public class FlyQiuFlowManageAutoConfig {

    public FlyQiuFlowManageAutoConfig() {
    }

    /**
     * 流程对象创建工厂
     *
     * @return {@link DefaultFlowObjectFactory}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowObjectFactory.class)
    public FlyQiuFlowObjectFactory flyQiuFlowObjectFactory() {
        return new DefaultFlowObjectFactory();
    }

    /**
     * 初始化流程配置
     *
     * @param flowObjectFactory 对象创建工厂
     * @return {@link DefaultFlowConfigImpl}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowConfig.class)
    public FlyQiuFlowConfig flyQiuFlyConfig(FlyQiuFlowObjectFactory flowObjectFactory) {
        return new DefaultFlowConfigImpl(flowObjectFactory);
    }

    /**
     * 获取元素配置
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowElementManage}}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowElementManage.class)
    public FlyQiuFlowElementManage flyQiuFlowElementManage(FlyQiuFlowObjectFactory flowObjectFactory) {
        return new DefaultFlyQiuFlowElementManage(flowObjectFactory);
    }


    /**
     * 获取脚本管理
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowScriptActuatorManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowScriptActuatorManage.class)
    public FlyQiuFlowScriptActuatorManage flyQiuFlowScriptManage() {
        return new DefaultFlyQiuFlowScriptActuatorManage();
    }

    /**
     * 格式管理
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowBpmnFormatManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowBpmnFormatManage.class)
    public FlyQiuFlowBpmnFormatManage bpmnFormatManage() {
        return new DefaultFlyQiuFlowBpmnFormatManage();
    }


    /**
     * 获取事件管理
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowEventManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowEventManage.class)
    public FlyQiuFlowEventManage flyQiuFlowEventManage() {
        return new DefaultFlyQiuFlowEventManage();
    }


    /**
     * 流程缓存管理
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowCacheManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowCacheManage.class)
    public FlyQiuFlowCacheManage flyQiuFlowCacheManage() {
        return new DefaultFlyQiuFlowCacheManage();
    }

    /**
     * 发布配置
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowDeployManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowDeployManage.class)
    public FlyQiuFlowDeployManage flyQiuFlowDeployManage() {
        return new DefaultFlyQiuFlowDeployManage();
    }

    /**
     * 候选人加载器
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiyFlowCandidateManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiyFlowCandidateManage.class)
    public FlyQiyFlowCandidateManage flyQiuFlowCandidateManage() {
        return new DefaultFlyQiuFlyCandidateManage();
    }


    /**
     * 变量管转换管理器
     * param flyQiuFlowEngine 流程引擎
     *
     * @return {@link FlyQiuFlowVarSerializeManage}
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFlowVarSerializeManage.class)
    public FlyQiuFlowVarSerializeManage flyQiuFlowVarSerializeManage() {
        return new DefaultFlyQiuFlowVarSerializeManage();
    }


}
